package vpfarm.gui;

import java.io.IOException;
import java.net.InetAddress;

import jtools.ai.agenten.AMessage;
import jtools.ai.agenten.Agent;
import jtools.network.mqueue.Adress;
import jtools.network.mqueue.MessageException;
import vpfarm.Constants;
import vpfarm.data.JobInfo;

public class SendJobAgent extends Agent {
	private JobInfo jobInfo;

	public SendJobAgent(JobInfo ji, String name, int port) throws IOException, MessageException {
		super(new Adress(InetAddress.getByName(name), port));
		this.jobInfo = ji;
	}
	
	public void onStart(){
		System.out.println("SendJobAgent onStart()");
		AMessage amsg = new AMessage(Constants.SEND_JOB_INFO);
		amsg.addReciver(Constants.MASTER_NAME);
		if (this.jobInfo == null)
			throw new NullPointerException("Jobinfo = null");
		amsg.setContent(this.jobInfo);
		sendMessage(amsg);
		System.out.println("Neuer Job gesendet");
	}
	
}
